/*
CParticle.cpp
Particle element

*/


#include "Particle.h"




CParticle::CParticle(void)
{

	m_fVelX_End		=	20;
	m_fVelX_Current	=	1;
	
	m_fVelY_End		=	20;
	m_fVelY_Current	=	1;

	
	
	m_fLife_Current =200;
	
	m_fScaleX_Current = 1;
	m_fScaleY_Current = 1;
	m_fRotation_Current = 1;
	
	m_fColorR_Current = 0;
	m_fColorG_Current = 0;
	m_fColorB_Current = 0;
	m_fColorA_Current = 255;
	m_fColorR_End = 255;
	m_fColorG_End = 255;
	m_fColorB_End = 255;
	m_fColorA_End = 255;
	

	m_fColorR_COT = (m_fColorR_End-m_fColorR_Current)/m_fLife_Current;
	m_fColorG_COT = (m_fColorG_End-m_fColorG_Current)/m_fLife_Current;
	m_fColorB_COT = (m_fColorB_End-m_fColorB_Current)/m_fLife_Current;
	m_fColorA_COT = (m_fColorA_End-m_fColorA_Current)/m_fLife_Current;
	this->SetHeight(64);
	this->SetWidth(64);
	//SetX(200);
	//SetY(200);
}


CParticle::~CParticle(void)
{
}


void CParticle::Update( float fElapsedTime )
{
	
	SetX(GetX()+ m_fVelX_Current*fElapsedTime);
	SetY(GetY()+m_fVelY_Current*fElapsedTime);
CEntity::Update(fElapsedTime);
	m_fLife_Current-=fElapsedTime;
	if(m_fVelX_Current<m_fVelX_End)
		m_fVelX_Current+= m_fVelX_VOT*fElapsedTime;
	if(m_fVelY_Current<m_fVelY_End)
		m_fVelY_Current+=  m_fVelY_VOT*fElapsedTime;
m_fColorR_Current +=	m_fColorR_COT*fElapsedTime;//*1000;
m_fColorG_Current +=	m_fColorG_COT*fElapsedTime;//*1000;
m_fColorB_Current +=	m_fColorB_COT*fElapsedTime;//*1000;
m_fColorA_Current +=	m_fColorA_COT*(fElapsedTime);//*1000);

m_fRotation_Current += m_fRotation_ROT*fElapsedTime;
if(m_fScaleX_Current<m_fScaleX_End)
	m_fScaleX_Current+= m_fScaleX_SOT*fElapsedTime;
if(m_fScaleY_Current<m_fScaleY_End)				  
	m_fScaleY_Current+= m_fScaleY_SOT*fElapsedTime;

}
void CParticle::Render( void )
{

	CSGD_TextureManager* pTM = CSGD_TextureManager::GetInstance();

	
	pTM->Draw( m_nImageID, this->GetX(),this->GetY(),m_fScaleX_Current, m_fScaleY_Current, nullptr,float(GetWidth()/2), float(GetHeight()/2),m_fRotation_Current,
		D3DCOLOR_ARGB((int)m_fColorA_Current,(int)m_fColorR_Current,(int)m_fColorG_Current,(int)m_fColorB_Current));
			   //float(GetWidth()/2), float(GetHeight()/2),m_fRotation_Current,D3DCOLOR_XRGB(255,255,255));
			   //D3DCOLOR_COLORVALUE(m_fColorR_Current,m_fColorG_Current,m_fColorB_Current,m_fColorA_Current));

}

bool CParticle::IsAlive(void)
{
	if(m_fLife_Current>=0)
		return true;
	else
		return false;
}
	void CParticle::SetScale(float X,float X2,float Y,float Y2)
	{
		m_fScaleX_Current=X;
		m_fScaleY_Current=Y;
		m_fScaleX_End=X2;
		m_fScaleY_End=Y2;
		m_fScaleX_SOT= (((m_fScaleX_End-m_fScaleX_Current)+1)/(m_fLife_Current+1));
		m_fScaleY_SOT= (((m_fScaleY_End-m_fScaleY_Current)+1)/(m_fLife_Current+1));  
	}

	void CParticle::SetRotation(float X,float Y)
	{
		m_fRotation_Current=X;
		m_fRotation_End=Y;
		if (X==Y)
			m_fRotation_ROT=0;
		else
		m_fRotation_ROT= (((m_fRotation_End-m_fRotation_Current)+1)/(m_fLife_Current+1)); 
	}